package com.dong.controller;

import com.dong.entity.Manager;
import com.dong.service.impl.ManagerServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/manager")
public class ManagerController {

    @Autowired
    private ManagerServiceImpl managerService;
    @GetMapping("/tologin")
    public String toLogin(){
        return "login";
    }
    @GetMapping("/tosuccess")
    public String toSuccess(){
        return "success";
    }
    @PostMapping("/login")
    public String login(String manager_name, String manager_pwd, HttpSession session){
        Manager manager = managerService.selectByNP(manager_name, manager_pwd);
        if(manager!=null){
            session.setAttribute("loginmanager",manager);
            return "redirect:/manager/tosuccess";
        }
        else {
            return "redirect:/manager/tologin";
        }
    }
    @RequestMapping("/exit")
    public String doExit(HttpSession session){
        //从session中移除
        session.removeAttribute("loginmanager");
        return "redirect:/manager/tologin";

    }

}

